package cn.edu.nit.sys.controller;

import cn.edu.nit.sys.entity.Course;
import cn.edu.nit.sys.service.CourseService;
import cn.edu.nit.sys.utils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/course")
@RestController
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping
    public R getList(Page<Course> page, String siftName, String siftTime) {
        return courseService.getCourseList(page, siftName, siftTime);
    }

    @GetMapping("/pc")
    public R getPcList(String uid, String siftTime) {
        return courseService.getPcList(uid, siftTime);
    }

    @PostMapping
    public R autowiredCourse(@RequestBody Course course) {
        if("0".equals(course.getAuto())) {
            return courseService.arrangeCourse(course);
        }
        return courseService.autoArrangeCourse(course.getStart());
    }

    @DeleteMapping("/{id}")
    public R delCourse(@PathVariable("id") String id) {
        return courseService.removeById(id) ? R.ok("删除成功") : R.error("删除失败");
    }

    @GetMapping("/{id}")
    public R getStudentCourse(String id, String time) {
        return courseService.getStudentCourse(id, time);
    }

    @GetMapping("/teacher/{id}")
    public R getTeacherCourse(String id, String time) {
        return courseService.getTeacherCourse(id, time);
    }

    @GetMapping("/year")
    public R getYearList() {
        return courseService.getYearList();
    }

    @GetMapping("/forteacher")
    public R getCourseForTeacher(String id, String siftTime) {
        return courseService.getCourseForTeacher(id, siftTime);
    }
}
